﻿<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>修改栏目 - 烫烫博客管理</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="apple-touch-icon-precomposed" href="/img/icon/icon.png">
<link rel="Shortcut Icon" href="favicon.ico" type="image/ico">
<script src="js/jquery-2.1.4.min.js"></script>
<!--[if gte IE 9]>
  <script src="js/jquery-1.11.1.min.js" type="text/javascript"></script>
  <script src="js/html5shiv.min.js" type="text/javascript"></script>
  <script src="js/respond.min.js" type="text/javascript"></script>
  <script src="js/selectivizr-min.js" type="text/javascript"></script>
<![endif]-->
<!--[if lt IE 9]>
  <script>window.location.href='upgrade-browser.html';</script>
<![endif]-->
</head>

<body class="user-select">
<section class="container-fluid">
  <header>
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">切换导航</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
          <a class="navbar-brand" href="/">烫烫</a> </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="/logout" onClick="if(!confirm('是否确认退出？'))return false;">退出登录</a></li>
          </ul>
          <form action="" method="post" class="navbar-form navbar-right" role="search">
            <div class="input-group">
              <input type="text" class="form-control" autocomplete="off" placeholder="键入关键字搜索" maxlength="15">
              <span class="input-group-btn">
              <button class="btn btn-default" type="submit">搜索</button>
              </span> </div>
          </form>
        </div>
      </div>
    </nav>
  </header>
  <div class="row">
    <aside class="col-sm-3 col-md-2 col-lg-2 sidebar">
      <ul class="nav nav-sidebar">
        <li><a href="/adminindex.html">关于</a></li>
      </ul>
      <ul class="nav nav-sidebar">
        <li ><a href="/show-article.html">文章</a></li>
      </ul>
      <ul class="nav nav-sidebar">
        <li ><a href="/tag.html">分类</a></li>
      </ul>
      <ul class="nav nav-sidebar">
        <li><a href="/tag.html">标签</a></li>
      </ul>
      <ul class="nav nav-sidebar">
        <li class="active"><a href="/link.html">友链</a></li>
      </ul>
    </aside>
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main">
      <h1 class="page-header">修改友链</h1>
      <form  method="post">
        <div class="form-group">
          <label for="link-name">友链名称</label>
          <input type="text" id="link-name"  value="" class="form-control" placeholder="在此处输入友链名称" required autocomplete="off">
          <span class="prompt-text">这将是它在站点上显示的名字。</span> </div>
        <div class="form-group">
          <label for="link-url">友链地址</label>
          <input type="text" id="link-url" name="alias" value="" class="form-control" placeholder="在此处输入友链地址" required autocomplete="off">
          <span class="prompt-text">地址。</span> </div>

        <button class="btn btn-primary" type="button" name="submit" onclick="update()">更新</button>
      </form>
    </div>
  </div>
</section>

<script src="js/bootstrap.min.js"></script> 
<script src="js/admin-scripts.js"></script>
<script src="/js/public-method.js"></script>


<script>

  //获得友链的原本内容
  function getlink(id) {
      $.ajax({
          url: "/link/selectLink",
          type:"post",
          dataType:"json",
          data:{"id": id},
          success :function (data) {
            $('#link-name').val(data.linkname);
            $('#link-url').val(data.url);
          },
          error:function (data) {
              alert("刷新失败")
          }
      })
  }

  //修改友链
  function update() {

      $.ajax({
          url:"/link/update",
          type:"POST",
          contentType : "application/json;charset=UTF-8",
          data:JSON.stringify({
              "linkid"    :getQueryString("id"),
              "linkname"  :$("#link-name").val(),
              "url" :$("#link-url").val()
          }),

          success:function (data) {
              if(data=="failed")
                  alert("更新失败")
              else
                  self.location='link.html';
          },
          error:function (data) {
              alert("更新error")
          }
      })
  }


    $(document).ready(function () {
        id=getQueryString("id")
        getlink(id)
    })
</script>
</body>
</html>
